//
// Created by wxd on 2025/8/15.
//

#pragma once

#ifndef PLANE_H
#define PLANE_H

#include "BaseGeometry.h"
#include <vector>
#include "../application/app/Application.h"

class Plane : public BaseGeometry {
public:
    Plane() : m_Width(0.f), m_Height(0.f), m_Normal(glm::vec3(0.f)), m_Center(glm::vec3(0.f)),
        m_Color(glm::vec3(0.f)) {
        m_DrawMode = GL_TRIANGLES;
        m_GeometryType = GeometryType::TRIANGLE;
        if (EngineApp.isGLInited()) {
            BaseGeometry::initVAO();
        }
    }

    Plane(float width, float height, glm::vec3 normal, glm::vec3 center) : m_Width(width), m_Height(height), m_Normal(normal), m_Center(center) {
        m_DrawMode = GL_TRIANGLES;
        m_DrawType = DrawType::DRAW_ELEMENTS;
        m_GeometryType = GeometryType::TRIANGLE;
        if (EngineApp.isGLInited()) {
            BaseGeometry::initVAO();
            raster();
        }
    }

    Plane(float width, float height, glm::vec3 normal, glm::vec3 center, glm::vec3 color) : m_Width(width), m_Height(height), m_Normal(normal), m_Center(center), m_Color(color) {
        m_DrawMode = GL_TRIANGLES;
        m_DrawType = DrawType::DRAW_ELEMENTS;
        m_GeometryType = GeometryType::TRIANGLE;
        if (EngineApp.isGLInited()) {
            BaseGeometry::initVAO();
            raster();
        }
    }

    std::unique_ptr<BaseGeometry> clone() const override {
        return std::make_unique<Plane>(*this);
    }

    void raster();

private:
    float m_Width;
    float m_Height;
    glm::vec3 m_Normal;
    glm::vec3 m_Center;
    glm::vec3 m_Color;

    std::vector<glm::vec3>  m_PlaneVertices;
    std::vector<glm::vec2>  m_PlaneTexCoords;
    std::vector<glm::vec3>  m_PlaneNormals;
    std::vector<glm::uvec3> m_PlaneFaces;
};



#endif //PLANE_H
